package cn.biplam.front.component.data.tree.nodeList;

import cn.biplam.common.paramters.TreeParam;
import cn.biplam.common.paramters.TreeParam.Index_Tree_Node_Type;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.Result;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.common.wrapper.treeFlat.flat.callback.OperatorTypeFilterCallback;
import cn.biplam.front.htmlscript.script.ScriptTreeNew;
import cn.biplam.front.template.control.rfFlowTable.callback.action.ActionCallback;

/**
 *  索引表树数据平面化后绑定到FlowTable
 * @author XiaoRuxing Nov 21, 20096:12:34 PM
 * @version 1.0
 */
public class IndexTreeChildList extends IndexChildList{

	/**
	 * 
	 * @param sHomeUrl      应用系统路径
	 * @param mUser         用户
	 * @param tablePageId   树的targetID
	 * @param recordId      树节点记录ID
	 */
	public IndexTreeChildList(
			String sHomeUrl,
			UserInfo mUser,
			String tablePageId,
			String recordId){
		super(sHomeUrl, mUser, tablePageId, recordId);
	}


	/**
	 *  
	 * @return 钻取动作回调器
	 */
	protected ActionCallback getDrillAction(String fieldName){
		TreeRefreshActionCallback action = new TreeRefreshActionCallback(
				this.treeParams.getByKey(TreeParam.TREE_PCID),
				this.treeParams.getByKey(TreeParam.TREE_AID), 
				this.treeParams.getByKey(TreeParam.TREE_INDEX), 
				fieldName);
		return action;
	}
	
	/**
	 * 索引表叶子节点类型过滤器
	 */
	class IndexTableLeafOperatorFilter implements OperatorTypeFilterCallback{

		public boolean isFilter(String operatorType) {
			if(operatorType.equals(Index_Tree_Node_Type.OTHER.toString())){
				return false;//未被过滤
			}else{
				return true;//被过滤
			}
		}

	}
	
	/**
	 * 数刷新脚本回调器
	 */
	class TreeRefreshActionCallback extends ActionCallback{
		
		private String pcid;
		private String actionId;
		private String treeIndex;
		
		public TreeRefreshActionCallback(String pcid,
				String actionId,
				String treeIndex,
				String keyField){
			this.pcid = pcid;
			this.actionId = actionId;
			this.treeIndex = treeIndex;
			this.setCustomerModel();//设置当前为非标准自定义脚本模式
			this.setKeyFieldName(keyField);
		}
		
		@Override
		public String getCustomerScript(Result result, String rowRecordId) throws ErrorMessage {
			return ScriptTreeNew.getRefresh(pcid, 
					actionId, 
					treeIndex, 
					this.getRecordId(result, rowRecordId), 
					true);
		}

		@Override
		public void process(Result result) {}
	}
}
